/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Chatree Siangklom
 * Created On : Feb 4, 2013  11:12:53 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.std
 * File Name : WorkerThread.java
 * TODO
 */
package com.tis.std;

import java.sql.Connection;

import jpa.entitys.synchro.staging.SyncQueue;

/**
 * @author chatree
 *
 */

public class WorkerThread implements Runnable {

    private String command;
    private Connection conn = null;
    private SyncQueue queue = null;
    
    public WorkerThread(String s, Connection conn, SyncQueue queue){
        this.command = s;
        this.conn = conn;
        this.queue = queue;
    }

    /**
     * (Javadoc)
     * @see java.lang.Runnable#run()
     * Date =Nov 12, 2013 : 3:14:01 PM 
     * CreateBy=Chatree Siangklom
     * TODO
     */
    public void run() {
        System.err.println(Thread.currentThread().getName()+ " Start. Command = "+command);
        processCommand();
        System.err.println(Thread.currentThread().getName()+" End. Command = "+command);
    }
    
    private void processCommand() {
    	QueueProcessing qServ = new QueueProcessing();
        try {
        	        	
			qServ.ProcRun(queue, conn);
			 
            //Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (Exception e) {
			e.printStackTrace();
		}finally{
			qServ = null;
		}
    }

    @Override
    public String toString(){
        return this.command;
    }
}